package com.example.rabbitmq.example.rabbitmq.ttl;

import com.rabbitmq.client.*;

import java.nio.charset.StandardCharsets;
import java.util.HashMap;
import java.util.Map;

public class Producer {

    public static void main(String[] args) throws Exception{
        ConnectionFactory factory = new  ConnectionFactory();
        factory.setUri("amqp://admin:admin@192.168.1.3:5672/%2f");
        final Connection connection = factory.newConnection();
        final Channel channel = connection.createChannel();

        Map<String, Object> arguments = new HashMap<>();
        arguments.put("x-message-ttl", 30000);
        arguments.put("x-expires", 10000);
        arguments.put("x-dead-letter-exchange", "exchange1");
        arguments.put("x-dead-letter-routing-key", "exchange1");
        channel.queueDeclare("queue.dlx", true, false,false, arguments);
        channel.queueBind("queue.dlx", "exchange1", "exchange1");
        channel.queueDeclare("queue1", true, false,false, arguments);
        channel.exchangeDeclare("exchange1", BuiltinExchangeType.DIRECT, true,false, null);
        channel.queueBind("queue1", "exchange1", "key.wq");
        channel.basicPublish("exchange1", "key.wq", new AMQP.BasicProperties().builder()
                .expiration("1000")
                .build(), ":".getBytes(StandardCharsets.UTF_8) );
    }
}
